package com.example.controller;

import com.example.pojo.JobDemand;
import com.example.service.IJobDemandService;
import com.example.vo.ResultVo;
import com.example.vo.per.DemandAppQuery;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 岗位需求计划表 前端控制器
 * </p>
 *
 * @author wsl
 * @since 2022-04-10
 */
@RestController
@RequestMapping("/jobDemand")
@Api(tags = "岗位需求计划表",value = "")
@CrossOrigin(allowCredentials = "true")
public class JobDemandController {

    @Autowired
    private IJobDemandService ijds;

    @GetMapping("/empbyjob")
    @ApiOperation("查询发布岗位人员")
    public ResultVo selJobDemByEmp() {
        List<Map<String, Object>> list = ijds.selEmpByJob();
        if (!list.isEmpty()){
            return ResultVo.response(list);
        }
        return ResultVo.error("暂时还没有人发布");
    }

    @GetMapping("")
    @ApiOperation("查询出可应聘的岗位")
    public ResultVo selByInit(){
        return ijds.selByNumStatus();
    }

    @PostMapping("/sav")
    @ApiOperation(value = "新增 - 需求申请")
    public ResultVo insav(@RequestBody JobDemand jrp){
        if (ijds.intjob(jrp) > 0) {
            return ResultVo.ok();
        } else {
            return ResultVo.error("需求申请提交错误！");
        }
    }

    /**
     *  pageSize  pageNum
     *  岗位名称  发布渠道  发布人 需求申请状态
     */
    @PostMapping("/selDemandSort")
    @ApiOperation(value = "多条件查询 - 需求申请")
    public PageInfo<JobDemand> getDemand(@RequestBody DemandAppQuery daq){
        System.err.println("JobDemC sel params" + daq);
        return ijds.selByMap(daq);
    }

    @DeleteMapping("/deljob")
    @ApiOperation("根据编号删除")
    public ResultVo delJobById(@RequestParam("ids") String[] ids){
        ijds.uptById(ids);
        return ResultVo.ok();
    }

    @PutMapping("/rel/{rid}")
    @ApiOperation("发布需求申请")
    public ResultVo delJobById(@PathVariable("rid") String id){
        Integer idStatus = ijds.uptByIdStatus(id,"发布");
        if (idStatus != 0){
            return ResultVo.ok();
        }else {
            return ResultVo.error("发布需求异常");
        }
    }

    @GetMapping("/uzero/{rid}")
    @ApiOperation("发布需求申请")
    public ResultVo uptJobZero(@PathVariable("rid") String id){
        Integer idStatus = ijds.uptByIdStatus(id,"取消");
        if (idStatus != 0){
            return ResultVo.ok();
        }else {
            return ResultVo.error("取消发布需求异常");
        }
    }

    @GetMapping("/sela/{rid}")
    @ApiOperation("查询需求申请")
    public JobDemand selJobById(@PathVariable("rid") String id){
        System.out.println(ijds.selById(id) + " ------- ");
        return ijds.selById(id);
    }
}
